package org.example.mine.controller;

import org.example.mine.service.WithdrawService;
import org.example.model.common.Result;
import org.example.model.domain.express.ExpressList;
import org.example.model.domain.mine.ExpressWithdraw;
import org.example.model.vo.mine.WithdrawVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/withdraw")
public class WithdrawController {


    @Autowired
    WithdrawService withdrawService;

    @Autowired
    RedisTemplate redisTemplate;
    @PostMapping("/addwithdrawrecord")
    public Result addwithdrawrecord(@RequestBody ExpressWithdraw expressWithdraw){
        String key = "COURIER:EXPRESS:LOGIN" + expressWithdraw.getRegisterIp();
        ExpressList expressListRedis = (ExpressList) redisTemplate.opsForValue().get(key);
        Integer realNameStatus = expressListRedis.getRealNameStatus();
        if(realNameStatus!=1){
            return Result.build(500,"请先实名认证");
        }
        withdrawService.addwithdrawrecord(expressWithdraw);
        return Result.build(200,"成功",expressWithdraw.getId());
    }

    @GetMapping("/getwithdrawrecord/{id}")
    public WithdrawVo getwithdrawrecord(@PathVariable("id") Long id){
        WithdrawVo withdrawVo=withdrawService.getwithdrawrecord(id);
        return withdrawVo;
    }

    @GetMapping("/getwithdrawdetailbyid/{id}")
    public ExpressWithdraw getwithdrawdetailbyid(@PathVariable("id") Integer id){
        ExpressWithdraw expressWithdraw=withdrawService.getwithdrawdetailbyid(id);
        return expressWithdraw;
    }

    @GetMapping("/getwithdrawmoneybyid/{registerIp}")
    public String getwithdrawmoneybyid(@PathVariable("registerIp") Long registerIp){
        String dailyIncome=withdrawService.getDailyIncome(registerIp);
        return dailyIncome;
    }
}
